from tkinter import Tk, Label, Button
from tkinter.filedialog import askopenfilenames
from PIL import Image, ImageTk
import os

image_paths = []
current_index = 0
image_descriptions = []  # 存储图片描述信息


def open_images():
    global image_paths, current_index, image_descriptions
    file_paths = askopenfilenames(filetypes=[("Image Files", "*.png;*.jpg;*.jpeg;*.bmp")])
    if file_paths:
        image_paths = list(file_paths)
        image_descriptions.clear()
        for path in image_paths:
            description = os.path.basename(path)  # 简单地使用文件名作为描述，可修改
            image_descriptions.append(description)
        show_image()


def show_image():
    global image_paths, current_index, img_label, description_label
    if image_paths:
        image_path = image_paths[current_index]
        image = Image.open(image_path)
        photo = ImageTk.PhotoImage(image)
        img_label.config(image=photo)
        img_label.image = photo
        description_label.config(text=image_descriptions[current_index])


def next_image():
    global current_index
    current_index = (current_index + 1) % len(image_paths)
    show_image()


def prev_image():
    global current_index
    current_index = (current_index - 1) % len(image_paths)
    show_image()


root = Tk()

open_btn = Button(root, text="打开图片", command=open_images)
open_btn.pack()

prev_btn = Button(root, text="上一张", command=prev_image)
prev_btn.pack()

next_btn = Button(root, text="下一张", command=next_image)
next_btn.pack()

img_label = Label(root)
img_label.pack()

description_label = Label(root)
description_label.pack()

root.mainloop()